package com.gufe.service.user.impl.community;

import com.gufe.dto.communitydto.PostCommentDTO;
import com.gufe.entity.PostComment;
import com.gufe.mapper.user.community.CommentMapper;
import com.gufe.service.user.community.CommentService;
import com.gufe.vo.communityvo.PostCommentVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    // 获取帖子对应的评论数据
    public List<PostCommentVO> getComments(Integer postId) {
        return commentMapper.getComments(postId);
    }

    // 新增评论
    public void addComment(PostCommentDTO postCommentDTO) {
        PostComment postComment = new PostComment();
        BeanUtils.copyProperties(postCommentDTO,postComment);
        commentMapper.addComment(postComment);
        commentMapper.updatePostCommentCount(postComment.getPostId());
    }
}
